package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;

import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import jdbc.entity.Departments;

public class DepartmentsDao {
	public List<Departments> findAll() {
		List<Departments> dep = new ArrayList<>();
		Connection con = Util.getCon();
		ResultSet rs;
		try {
			Statement sta = con.createStatement();
			rs = sta.executeQuery("select * from departments");
			while (rs.next()) {
				Departments d = new Departments();
				d.setDepartment_id(rs.getInt(1));
				d.setDepartment_name(rs.getString(2));
				d.setLocation_id(rs.getInt(3));
				d.setManager_id(rs.getInt(4));
				dep.add(d);
			}

		} catch (Exception e) {

			e.printStackTrace();
		}

		return dep;
	}
}
